package org.miyuki4j.cfgtool.app.gui;

import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.stage.Stage;
import org.miyuki4j.cfgtool.CfgAppKeeper;

import java.util.Objects;

public class MainGui extends Application {

    static Stage primaryStage;

    static Parent mainGui;

    public static void main(String[] args) {
        launch(MainGui.class, args);
    }

    static void setParent(Parent parent) {
        primaryStage.getScene().setRoot(parent);
    }

    static void back() {
        setParent(mainGui);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        MainGui.primaryStage = primaryStage;
        mainGui = Objects.requireNonNull(SceneLoader.loadParent("MainGui.fxml"));
        Scene scene = new Scene(mainGui, 1080, 640);
        primaryStage.setTitle("打表工具");
        primaryStage.setScene(scene);
        primaryStage.setResizable(true);
        primaryStage.setOnCloseRequest(event -> CfgAppKeeper.done());
        primaryStage.show();
    }

    static void showAlert(String message){
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("提示");
        alert.setHeaderText(null);
        alert.setContentText(message);
        alert.showAndWait();
    }
}